<template>
	<div class="my_l">
		<header class="top_bar">
		    <a @click="tuihui" class="icon_back"></a>
		    <h3 class="cartname">京东登录</h3>
		</header>
		<main class="user_login_box">
		    <div class="login_dialog">
		        <div class="_username">
		            <input type="text" name="username" placeholder="请输入用户名" class="user_input" v-model="username"/>
		        </div>
		        <div class="_username u_passwd">
		            <input type="password" name="password" placeholder="请输入密码" class="user_input" v-model="password"/>
		        </div>
				<mu-flex style="z-inxex:1002" justify-content="center" align-items="center">
					<mu-button @click="goLogin" full-width color="primary">登录</mu-button>
				</mu-flex>
		        <div class="go_reg_box">
		            <!-- <router-link style="cursor:pointer" tag="span" to="/register">快速注册</router-link> -->
					<mu-button @click="goSearch11" flat color="primary">快速注册</mu-button>
		        </div>
		    </div>
		</main>
	</div>
</template>
<script>
import {Message} from 'element-ui'
export default {
		data(){
			return{
				username:'',
				password:'',
				userInfo:{}
			}
		},
		methods:{
			goLogin(){
				if(this.username ===''){
					alert('请输入用户名');
				}else if(this.password === ''){
					alert('请输入密码');
				}else{
					this.$axios.post('/login',{
						loginName:this.username,
						loginPawd:this.password,
					}).then((res)=>{
						console.log('ressd', res)
					if(res.status === 200){
						this.userInfo = res.database;
						console.log('this.userinfo', this.userInfo)
						this.$_global.forceLogined = true
							window.sessionStorage.userInfo = JSON.stringify(this.userInfo);
							// this.$store.dispatch('setUserInfo', this.userInfo);
							this.saveUserInfo(this.userInfo)
							this.$store.dispatch('hideLoading')
							this.$toast.success({
								position: 'top',
								message: '登录成功'
							});
							// let redirect = decodeURIComponent(this.$route.query.redirect || '/');
                        	// this.$router.push({
							// 	path: redirect,
							// 	replace: true
							// });
							// this.$router.push('/home')
							// alert(res.msg);
							// this.$message.success(res.msg)
					}else{
						this.$toast.error({
								position: 'top',
								message: res.msg
							});
					}
					});
				}
				
			},
			// 存储登录信息
			saveUserInfo (userInfo) {
				this.$store.dispatch('setUserInfo', userInfo).then(() => {
					this.$router.push('/home')
				})
			},
			tuihui () {
				this.$router.go(-1)
			},
			goSearch11 () {
				this.$router.push('/register')
			}
		}
	}
</script>
<style>
@import '../assets/css/login.css';
</style>